<?php
class indexMod extends commonMod
{
	public function __construct()
	{
		parent::__construct();

	}
//显示管理后台首页
	public function index()
	{	
			global $config;
			$this->assign('config',$config);	
			$this->display();
	}
//登录页面
	public function login()
	{
		if(empty($_POST['do']))
		{
			$this->display('index/login');
			return;
		}
		//获取数据
		$username=in($_POST['username']);
		$password=md5($_POST['password']);

		//数据验证
		if(empty($username))
		{
			$this->error('请输入用户名');
		}
		if(empty($_POST['password']))
		{
			$this->error('请输入密码');		
		}
		/*
		if(empty($_POST['checkcode']))
		{
			$this->error('请输入验证码');
		}
				
		if($_POST['checkcode']!=$_SESSION['verify'])
		{
			$this->error('验证码错误，请重新输入');
		}
		*/
		//数据库操作
		switch ($this->_login($username,$password)){
			case 'Lock':
				$this->error('工号或密码错误，请重新输入');
			break;
			case 'Lockupdate':
				$this->redirect(__APP__);
			break;
			default:
				$this->error("帐号尚未激活，请联系人事经理激活帐号！");
			break;
		}
		
	}
//用户登录
	private function _login($username,$password)
	{
		$condition=array();
		$condition['username']=$username;
		$user_info=$this->model->table('admin')->where($condition)->find();
		//用户名密码正确且没有锁定
		
		if($user_info['isLock']==0){
			$login_progress = 'Lock';
			if($user_info['password']==$password)
			{			
				//更新帐号信息
				$data=array();			
				$data['login_time'] = time();
				$data['login_ip']   = get_client_ip();
				//$data['logCount']  = intval($user_info['logCount'])+1;
				$this->model->table('admin')->data($data)->where($condition)->update();
				
				//设置登录信息
				$_SESSION['uid']=$user_info['id'];
				$_SESSION['username']=$user_info['username'];
				$_SESSION['groupid']=$user_info['groupid'];
						
				$login_progress .= 'update';
			}
		}
		return $login_progress;		
	}	
	
//用户退出
	public function logout()
	{
		unset($_SESSION['uid']);
		unset($_SESSION['username']);
		unset($_SESSION['groupid']);
		$this->success('您已成功退出系统',__APP__);
	}
//生成验证码
	public function verify()
	{
		require_once(CP_PATH.'lib/Image.class.php');
		Image::buildImageVerify();
	}
/*
欢迎页面
*/
	public function welcome()
	{
		//$this->assign('user_info',$user_info);
		$this->display();
	}
	
	public function top(){
		$this->display();
	}
	
	public function center(){
		$this->display();
	}
	
	public function down(){
		$this->display();
	}
	
	public function middel(){
		$this->display();
	}
	
	public function left(){
		$this->display();
	}
}
?>